<template>
	<!-- 返修领料单 -->
	<div class="app-container">
		<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" class="queryForms"
			label-width="85px">
			<el-form-item label="返修任务单" prop="repairNumber">
				<el-input v-model="queryParams.repairNumber" placeholder="请输入返修任务单" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="物料名称" prop="partName">
				<el-input v-model="queryParams.partName" placeholder="请输入物料名称" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="产品图号" prop="productModel">
				<el-input v-model="queryParams.productModel" placeholder="请输入产品图号" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>

			<el-form-item label="生产批次" prop="productionBatch">
				<el-input v-model="queryParams.productionBatch" placeholder="请输入生产批次" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="物料编码" prop="partFigure">
				<el-input v-model="queryParams.partFigure" placeholder="请输入物料编码" clearable
					@keyup.enter.native="handleQuery" maxlength="20" show-word-limit />
			</el-form-item>
			<el-form-item label="状态" prop="materialApprovalStatus">
				<el-select v-model="queryParams.materialApprovalStatus">
					<el-option v-for="item in dict.type.default_approve" :key="item.value" :value="item.value"
						:label="item.label"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
				<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
			</el-form-item>
		</el-form>

		<el-row :gutter="10" class="mb8">
			<el-col :span="1.5">
				<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleSubmits"
					v-hasPermi="['taskFilling:repairList:submit']">提交</el-button>
			</el-col>
			<!-- <el-col :span="1.5">
				<el-button type="primary" icon="el-icon-plus" size="mini" @click="handleApprove({})" v-hasPermi="['taskFilling:repairList:approve']">审批</el-button>
			</el-col> -->
			<CreateForm :ids="ids" :rows="rows" formtype="t_repair_material" />
			<right-toolbar @changeTableData="changeTableData" menuNames="repairList79" :showSearch.sync="showSearch"
				@queryTable="handleQuery" :columns.sync="columns" perm="taskFilling:repairList:index"></right-toolbar>
		</el-row>
		<!--  -->
		<div :class="sidebar.opened && eleTabTop <= 85 ? 'eleTab' : !sidebar.opened && eleTabTop <= 85 ? 'eleTabs' : ''"
			class="informationTab" ref="eleTab">
			<el-table :key="treetablekey" @expand-change="handleExpandChange" :row-class-name="row_class_name"
				@mousedown.native="mousedownTable" @row-click="row_click" @cell-mouse-enter="cell_mouse_enter"
				@cell-mouse-leave="cell_mouse_leave" @mouseup.native="mouseupTable" @mouseleave.native="mouseupTable"
				ref="multipleTable" v-loading="loading" :data="RepairList" @selection-change="handleSelectionChange"
				row-key="id" lazy :load="loadListDes" :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
				border height="100%">
				<el-table-column type="selection" width="55" align="center" />
				<el-table-column label="序号" align="center" type="index" width="55">
					<template slot-scope="scope">
						<div>{{ scope.row.sort }}</div>
					</template>
				</el-table-column>
				<!-- <el-table-column label="编号" prop="materialNumber" min-width="250" :show-overflow-tooltip="true" v-if="columns[0].visible" /> -->
				<el-table-column label="外协单位" prop="outsourcedUnit" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[0].visible" />
				<el-table-column label="返修任务单" prop="repairNumber" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[1].visible" />
				<el-table-column label="工艺通知单" prop="processNumber" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[2].visible" />
				<el-table-column label="产品图号" prop="productModel" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[3].visible" />
				<el-table-column label="生成日期" align="center" prop="createTime" min-width="220"
					:show-overflow-tooltip="true" v-if="columns[12].visible">
					<template slot-scope="scope">
						<el-date-picker v-if="scope.row.hasChildren" @change="updateTime(scope.row)"
							style="width: 180px" v-model="scope.row.createTime" type="date" placeholder="选择日期"
							format="yyyy-MM-dd" value-format="yyyy-MM-dd"> </el-date-picker>
						<span v-else>{{ parseTime(scope.row.createTime, "{y}-{m}-{d}") }}</span>
					</template>
				</el-table-column>
				<el-table-column label="生产批次" prop="productionBatch" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[4].visible" />
				<el-table-column label="物料编码" prop="partFigure" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[5].visible" />
				<el-table-column label="物料名称" prop="partName" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[6].visible" />
				<el-table-column label="需求数" align="center" prop="partQuantity" min-width="150"
					:show-overflow-tooltip="true" v-if="columns[7].visible" />
				<el-table-column label="领料原因" prop="replacementSituation" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[8].visible" />
				<el-table-column label="零件状态" align="center" prop="inspectStatus" min-width="150"
					:show-overflow-tooltip="true" v-if="columns[9].visible">
					<template slot-scope="scope">
						<div v-if="scope.row.hasChildren">
							<div v-if="scope.row.inspectStatus == '零件齐全'">
								<el-tag type="success"> {{ scope.row.inspectStatus }}</el-tag>
							</div>
							<div v-if="scope.row.inspectStatus == '零件缺失'">
								<el-tag type="warning"> {{ scope.row.inspectStatus }}</el-tag>
							</div>
						</div>
						<div v-else>
							<dict-tag :options="dict.type.inspect_status" :value="scope.row.inspectStatus" />
						</div>
					</template>
				</el-table-column>
				<!-- <el-table-column label="合格证号" prop="certificateNumber" min-width="150" :show-overflow-tooltip="true" v-if="columns[10].visible" /> -->
				<el-table-column label="状态" align="center" prop="materialApprovalStatus" min-width="150"
					:show-overflow-tooltip="true" v-if="columns[10].visible">
					<template slot-scope="scope">
						<el-tag type="info" v-if="scope.row.materialApprovalStatus === '0'" class="disableClick">
							<dict-tag :options="dict.type.default_approve" :value="scope.row.materialApprovalStatus" />
						</el-tag>
						<el-tag v-if="scope.row.materialApprovalStatus === '1'" class="clickable">
							<dict-tag :options="dict.type.default_approve" :value="scope.row.materialApprovalStatus" />
						</el-tag>
						<el-tag type="success" v-if="scope.row.materialApprovalStatus === '2'" class="clickable">
							<dict-tag :options="dict.type.default_approve" :value="scope.row.materialApprovalStatus" />
						</el-tag>
						<el-tag type="danger" v-if="scope.row.materialApprovalStatus === '3'" class="clickable">
							<dict-tag :options="dict.type.default_approve" :value="scope.row.materialApprovalStatus" />
						</el-tag>
					</template>
				</el-table-column>

				<el-table-column label="器材库" prop="equipmentFlag" min-width="150" :show-overflow-tooltip="true"
					v-if="columns[11].visible">
					<template slot-scope="scope">
						<div v-if="scope.row.equipmentFlag == 0">机轮库</div>
						<div v-if="scope.row.equipmentFlag == 1">器材库</div>
					</template>
				</el-table-column>
				<el-table-column label="操作" class-name="small-padding fixed-width" width="200px" fixed="right">
					<template slot-scope="scope">
						<section v-if="scope.row.hasChildren">
							<el-button size="mini" type="text" icon="el-icon-circle-check"
								@click="handleSubmit(scope.row)"
								v-if="scope.row.materialApprovalStatus == '0' || scope.row.materialApprovalStatus == '3'"
								v-hasPermi="['taskFilling:repairList:submit']">提交</el-button>
							<!-- 审批中显示 -->
							<!-- <el-button size="mini" type="text" icon="el-icon-edit" @click="handleApprove(scope.row)" v-if="scope.row.materialApprovalStatus == '1' && scope.row.existApprovalStatus == '0'" v-hasPermi="['taskFilling:repairList:approve']">审批</el-button> -->
							<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)"
								v-hasPermi="['taskFilling:repairList:remove']">删除</el-button>
							<el-button size="mini" type="text" icon="el-icon-wallet" @click="handleAnnex(scope.row)"
								v-hasPermi="['taskFilling:repairList:annex']">附件</el-button>
						</section>
						<section v-else>
							<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
								v-hasPermi="['taskFilling:repairList:edit2']">修改</el-button>
							<el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete2(scope.row)"
								v-hasPermi="['taskFilling:repairList:remove2']">删除</el-button>
						</section>
					</template>
				</el-table-column>
			</el-table>
		</div>

		<pagination menuNames="Pagination82" v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
			:limit.sync="queryParams.pageSize" @pagination="getList" />

		<!-- 新增 -->
		<el-dialog :title="title" :visible.sync="open" width="900px" append-to-body v-dialogDrag>
			<el-form ref="form" :model="form" :rules="rules" label-width="80px" class="add-form2">
				<el-form-item label="物料名称" prop="partName">
					<el-input v-model="form.partName" disabled />
				</el-form-item>
				<el-form-item label="物料编码" prop="partFigure">
					<el-input v-model="form.partFigure" disabled />
				</el-form-item>
				<el-form-item label="需求数量" prop="partQuantity">
					<el-input v-model="form.partQuantity" placeholder="请输入需求数量" maxlength="20" show-word-limit />
				</el-form-item>
				<el-form-item label="领料原因" prop="replacementSituation">
					<el-input v-model="form.replacementSituation" placeholder="请输入领料原因" maxlength="20"
						show-word-limit />
				</el-form-item>
				<el-form-item label="器材库" prop="equipmentFlag">
					<el-select v-model="form.equipmentFlag">
						<el-option v-for="item in equipmentList" :key="item.id" :label="item.name"
							:value="item.id"></el-option>
					</el-select>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button type="primary" @click="submitForm">确 定</el-button>
				<el-button @click="cancel">取 消</el-button>
			</div>
		</el-dialog>

		<!-- 审批弹框 -->
		<el-dialog title="审批" :visible.sync="openApprove" width="900px" append-to-body v-dialogDrag>
			<ApproveTemplete @cancelApprove="cancelApprove" :openApprove="openApprove"></ApproveTemplete>
		</el-dialog>   
		<!-- 审批流程弹框 -->
		<el-dialog title="审批流程" :visible.sync="openRecords" width="900px" append-to-body v-dialogDrag>
			<RecordsTemplete :approveRecord="approveRecord"></RecordsTemplete>
		</el-dialog>
	</div>
</template>

<script>
import { editrepairMaterial, listRepair, listRepairChild, addRepair, generateMaterial, getRepair, getProductList, delProductList, submitProduction, productionApprove, delProductListChild, getProductInfo, editProductInfo } from "@/api/taskFilling/repairList"
import ApproveTemplete from "@/views/components/ApproveTemplete"
import RecordsTemplete from "@/views/components/RecordsTemplete"
import { approvalRecord } from "@/api/productTechnology/productTechnologyVersions"
import CreateForm from "@/views/components/CreateForm"
import { mapGetters } from "vuex"
import { getcolumn } from "@/api/selectList"
import searchStateMixin from '@/layout/mixin/searchStateMixin.js'
export default {
	name: "RepairList",
	mixins: [searchStateMixin],
	dicts: ["flow_status", "default_approve", "inspect_status"],
	components: { ApproveTemplete, RecordsTemplete, CreateForm },
	computed: {
		...mapGetters(["sidebar"])
	},
	data() {
		return {
			tableTreeRefreshTool: {}, // 用于存储 resolve 方法和展开状态
			isMousedownTable: false, //是否按下表格
			currentEnterRow: null, //当前移入的行数据
			equipmentList: [
				{
					id: "0",
					name: "机轮库"
				},
				{
					id: "1",
					name: "器材库"
				}
			],
			eleTabTop: 0, //表格容器距浏览器顶部距离
			testval: undefined,
			// 遮罩层
			loading: true,
			// 选中数组
			ids: [],
			// 选中数组列表
			rows: [],
			// 非单个禁用
			single: true,
			// 非多个禁用
			multiple: true,
			// 显示搜索条件
			showSearch: true,
			// 总条数
			total: 0,
			// 生产计划表格数据
			RepairList: [],
			// 弹出层标题
			title: "",
			// 是否显示弹出层
			open: false,
			// 查询参数
			queryParams: {
				pageNum: 1,
				pageSize: 10,
				repairNumber: undefined,
				partName: undefined,
				productModel: undefined,
				productionBatch: undefined,
				partFigure: undefined
			},
			// 表单参数
			form: {},
			// 表单校验
			rules: {
				partQuantity: [{ required: true, message: "请填写需求数量", trigger: "blur" }],
				replacementSituation: [{ required: true, message: "请输入领料原因", trigger: "blur" }],
				// certificateNumber: [{ required: true, message: "请输入合格证号", trigger: "blur" }],
				equipmentFlag: [{ required: true, message: "请选择器材库", trigger: "blur" }]
			},
			deviceList: [],
			// 修改保养计划弹框
			changeOpen: false,
			changeTitle: "",
			changeForm: {},
			ruleMonths: [],
			changeDisabled: false,
			// 更新树刷新
			treeMap: new Map(),
			isOne: true, // 是否是单条制定计划
			// 返修任务详情
			openDetail: false,
			// 生成领料单
			receiveFormOpen: false,
			receiveForm: {},
			// 产品列表
			productList: [],
			// 审批数据
			openApprove: false,
			approveRow: undefined,
			// 审批流程
			openRecords: false,
			approveRecord: [],
			treetablekey: Math.random(),
			// 列信息
			columns: [
				{ key: 0, label: `外协单位`, visible: true },
				{ key: 1, label: `返修任务单`, visible: true },
				{ key: 2, label: `工艺通知单`, visible: true },
				{ key: 3, label: `产品图号`, visible: true },
				{ key: 4, label: `生产批次`, visible: true },
				{ key: 5, label: `物料编码`, visible: true },
				{ key: 6, label: `物料名称`, visible: true },
				{ key: 7, label: `需求数`, visible: true },
				{ key: 8, label: `领料原因`, visible: true },
				{ key: 9, label: `零件状态`, visible: true },
				// { key: 10, label: `合格证号`, visible: true },
				{ key: 10, label: `状态`, visible: true },
				{ key: 11, label: `器材库`, visible: true },
				{ key: 12, label: `生成日期`, visible: true }
			]
		}
	},
	created() {
		// 如果是页面刷新，重置查询
		if (window.performance && performance.navigation.type === performance.navigation.TYPE_RELOAD) {
			this.resetForm("queryForm")
			// 清除URL中的查询参数（不刷新页面）
			window.history.replaceState({}, document.title, window.location.pathname)
		}
		// this.getSize()
	},
	mounted() {
		// 滚动条的获取
		this.handleScrollx()
		window.addEventListener("scroll", this.handleScrollx, true)
	},
	watch: {
		"$route.query": {
			handler(newQuery, oldQuery) {
				if (newQuery.queryData) {
					if (Object.keys(newQuery.queryData).length === 0) {
						this.resetQuerys()
						// this.getSize()
					} else {
						this.queryParams = { ...this.queryParams, ...JSON.parse(newQuery.queryData) }
						// this.getSize()
					}
				} this.getSize()
			},
			immediate: true, // 立即执行一次
			deep: true // 深度监听 
		}
	},
	activated() {
		// this.getSize()
		//获取表格容器距页面头部的距离
		this.handleScrollx()
	},
	destroyed() {
		window.removeEventListener("scroll", this.handleScrollx, true)
	},
	methods: {
		getSize() {
			getcolumn({ pageName: "Pagination82" }).then(response => {
				this.queryParams.pageSize = response.data.length ? (response.data[0].limit ? response.data[0].limit : 10) : 10
				this.getList()
			})
		},
		updateTime(row) {
			row.createTime = row.createTime + " 00:00:00"
			editrepairMaterial(row).then(res => {
				this.$modal.msgSuccess("修改成功")
				this.getList()
			})
		},
		//获取表格容器距页面头部的距离
		handleScrollx() {
			this.eleTabTop = this.$refs.eleTab.getBoundingClientRect().top
		},
		// 新增产品列表
		async getProductList(row) {
			let ret = await getProductList({ repairId: row.id })
			this.productList = ret.rows
		},
		// 删除子列表零件
		handleDelete2(row) {
			let id = row.id.replace("c", "")
			this.$modal
				.confirm("是否确认删除数据项？")
				.then(function () {
					return delProductListChild(id)
				})
				.then(() => {
					this.$modal.msgSuccess("删除成功")
					this.refreshLoadTree(row.repairMaterialId) // 刷新子级数据
					this.$nextTick(() => {
						this.$refs.multipleTable.doLayout()
					})
				})
				.catch(() => { })
		},
		/** 查询生产计划列表 */
		getList() {
			this.loading = true
			listRepair(this.queryParams).then(response => {
				this.RepairList = response.rows
				this.RepairList.forEach((item, index) => {
					; (item.hasChildren = true), (item.sort = index + 1)
				})
				this.total = response.total
				this.loading = false
			})
		},

		refreshLoadTree(parentId) {
			const { tree, treeNode, resolve } = this.treeMap.get(parentId)
			this.loadListDes(tree, treeNode, resolve) // 重新加载子级数据
			this.$refs.multipleTable.clearSelection()
		},
		/** 提交按钮 */
		submitForm() {
			this.$refs["form"].validate(valid => {
				if (valid) {
					editProductInfo(this.form).then(response => {
						this.$modal.msgSuccess("操作成功")
						this.open = false
						this.refreshLoadTree(this.form.repairMaterialId) // 刷新子级数据
					})
				}
			})
		},
		// 关闭所有展开的行
		closeAllExpansions() {
			this.RepairList.forEach(row => {
				this.$refs.multipleTable.toggleRowExpansion(row, false)
			})
			if (this.$refs.multipleTable) {
				this.$refs.multipleTable.clearSelection()
			}

			this.getList()
		},
		// 展开/收起时触发
		handleExpandChange(row, expanded) {
			const curr = this.tableTreeRefreshTool[row.id]
			if (!curr) return
			curr.expandCount++
			if (expanded && curr.expandCount > 1 && !curr.prevStatus) {
				let queryParams = JSON.parse(JSON.stringify(this.queryParams))
				delete queryParams.pageSize
				delete queryParams.pageNum
				listRepairChild({
					repairMaterialId: row.id,
					...queryParams
				}).then(res => {
					res.rows.forEach((item, index) => {
						// 父子id会冲突
						item.id = "c" + item.id
						item.sort = index + 1
					})
					curr.resolve(res.rows)
				})
			}
			curr.prevStatus = expanded
		},
		// 获取列表子菜单
		async loadListDes(tree, treeNode, resolve) {
			if (!this.treeMap.has(tree.id)) {
				this.treeMap.set(tree.id, { tree: tree, treeNode, resolve })
			}
			this.tableTreeRefreshTool[tree.id] = {
				resolve,
				expandCount: 0, // 展开次数
				prevStatus: false // 上一次的展开状态
			}
			let queryParams = JSON.parse(JSON.stringify(this.queryParams))
			delete queryParams.pageSize
			delete queryParams.pageNum
			let data = {
				repairMaterialId: tree.id,
				...queryParams
			}
			let ret = await listRepairChild(data)
			tree.hasChildren = ret.rows.length > 0
			tree.children = ret.rows
			if (ret.rows.length == 0) {
				resolve([]) // 确保返回空数组
				this.$set(this.$refs.multipleTable.store.states.lazyTreeNodeMap, tree.id, [])
			} else {
				ret.rows.forEach((item, index) => {
					item.id = "c" + item.id
					item.sort = index + 1
				})
				resolve(ret.rows)
			}
		},
		// 取消按钮
		cancel() {
			this.open = false
			this.reset()
		},
		// 表单重置
		reset() {
			this.form = {
				partName: undefined,
				partFigure: undefined,
				partQuantity: undefined,
				replacementSituation: undefined,
				certificateNumber: undefined
			}
			this.resetForm("form")
		},
		// 表单重置，生成领料单
		resetReceive() {
			this.receiveForm = {
				ids: undefined,
				materialNumber: undefined,
				outsourcedUnit: undefined
			}
			this.resetForm("receiveForm")
		},
		/** 搜索按钮操作 */
		handleQuery() {
			this.queryParams.pageNum = 1
			this.saveSearchState()
			this.closeAllExpansions()
			this.getList()
			this.treetablekey = Math.random()
		},
		resetQuerys() {
			this.resetForm("queryForm")
			this.queryParams = {
				pageNum: 1,
				pageSize: this.queryParams.pageSize,
				repairNumber: undefined,
				partName: undefined,
				productModel: undefined,
				productionBatch: undefined,
				partFigure: undefined
			}
		},
		/** 重置按钮操作 */
		resetQuery() {
			this.resetForm("queryForm")
			this.queryParams = {
				pageNum: 1,
				pageSize: this.queryParams.pageSize,
				repairNumber: undefined,
				partName: undefined,
				productModel: undefined,
				productionBatch: undefined,
				partFigure: undefined
			}
			this.clearSearchCache()
			this.handleQuery()
		},
		mousedownTable(event) {
			const target = event.target
			// 判断target的class属性确定是否点击在复选框上
			if (target.classList.contains("el-checkbox__inner")) {
				this.currentEnterRow && this.$refs.multipleTable.toggleRowSelection(this.currentEnterRow)
				this.isMousedownTable = true
			}
		},
		// 单击表格行
		row_click(row, column, event) {
			if (column && column.label == "操作") {
				return
			} else {
				this.$refs.multipleTable.toggleRowSelection(row)
			}
			// this.currentEnterRow || this.$refs.table.toggleRowSelection(row)
		},
		changeTableData() {
			this.$nextTick(() => {
				this.$refs.multipleTable.doLayout()
			})
		},

		// 进入单元格
		cell_mouse_enter(row, column, cell, event) {
			this.isMousedownTable && this.$refs.multipleTable.toggleRowSelection(row)
			this.currentEnterRow = row
		},
		// 离开单元格
		cell_mouse_leave(row, column, cell, event) {
			this.currentEnterRow = null
		},
		// 鼠标弹起或者离开表格
		mouseupTable(d) {
			this.isMousedownTable = false
		},
		// 表格每行样式
		row_class_name({ row, rowIndex }) {
			return this.rows.find(v => v.id == row.id) ? "selected" : ""
		},
		// 多选框选中数据
		handleSelectionChange(selection) {
			this.ids = selection.map(item => item.id)
			this.rows = selection
			this.single = selection.length !== 1
			this.multiple = !selection.length
		},
		/** 修改按钮操作 */
		handleUpdate(row) {
			this.reset()
			const id = row.id.replace("c", "")
			getProductInfo(id).then(response => {
				this.form = response.data
				this.open = true
				this.title = "修改零组件"
			})
		},

		// 换件单
		// handleChange(row) {
		//   let id = row.id.replace("c", "");
		//   let url = "/taskFilling/change?id=" + id;
		//   this.$router.push(url);
		// },
		/** 删除按钮操作 */
		handleDelete(row) {
			const ids = row.id || this.ids
			this.$modal
				.confirm("是否确认删除数据项？")
				.then(function () {
					return delProductList(ids)
				})
				.then(() => {
					this.getList()
					this.$refs.multipleTable.clearSelection()
					this.$modal.msgSuccess("删除成功")
				})
				.catch(() => { })
		},

		handleSubmits() {
			let checkp = this.rows.every(item => {
				return typeof item.id == "number"
			})
			if (!checkp) {
				this.$modal.msg("只能选择父级产品进行提交")
				return false
			}
			const _this = this
			this.$modal
				.confirm(`是否确认提交数据？`)
				.then(function () {
					return submitProduction({
						workIds: _this.ids,
						workflowType: "6"
					})
				})
				.then(() => {
					_this.getList()
					localStorage.setItem("todoMessage", "repairList1")
					_this.$modal.msgSuccess("提交成功")
					_this.$refs.multipleTable.clearSelection()
				})
				.catch(() => { })
		},
		// 列表父级提交
		handleSubmit(row) {
			this.$modal
				.confirm("是否确认提交数据项？")
				.then(function () {
					let data = {
						workId: row.id,
						workflowType: "6",
						// 1是提交，3是重复提交
						submitStatus: row.materialApprovalStatus == "0" ? "1" : "2"
					}
					return submitProduction(data)
				})
				.then(() => {
					this.getList()
					localStorage.setItem("todoMessage", "repairList2")
					this.$modal.msgSuccess("操作成功")
					this.$refs.multipleTable.clearSelection()
				})
				.catch(() => { })
		},
		// 附件
		handleAnnex(row) {
			this.$router.push({
				path: "/attachment/attachmentUpload",
				query: {
					TableId: row.id,
					typeId: 16,
					perm: "taskFilling:repairList:annex",
					// queryParams: JSON.stringify(this.queryParams),
					paths: "/taskFilling/repairList"
				}
			})
		},
		// 审批
		handleApprove(row) {
			if (row.id) {
				this.approveRow = {
					id: row.hasChildren ? row.id : row.id.substring(3),
					status: row.hasChildren ? true : false,
					repairId: row.repairId
				}
				this.openApprove = true
			} else {
				this.approveRow = {}
				let checkp = this.rows.every(item => {
					return typeof item.id == "number"
				})
				if (!checkp) {
					this.$modal.msg("只能选择父级产品进行审批")
					return false
				}
				this.openApprove = true
			}
		},

		// 审批取消
		async cancelApprove(ret) {
			if (!ret.flag) {
				this.openApprove = false
				return false
			}
			let data = {
				approvalStatus: ret.approvalStatus,
				causeRejection: ret.causeRejection,
				workflowType: "6"
			}
			this.approveRow.id ? (data.id = this.approveRow.id) : (data.ids = this.ids)
			let res = await productionApprove(data)
			if (res.code == 200) {
				this.$modal.msgSuccess("操作成功")
				this.getList()
				this.$refs.multipleTable.clearSelection()
			}
			this.openApprove = false
		},
		// 获取审批详情
		showApproveList(row) {
			if (row.approvalStatus == "0") {
				return false
			}
			this.openRecords = true
			approvalRecord({
				id: row.id,
				workflowType: "6"
			}).then(res => {
				this.openRecords = true
				this.approveRecord = res.data
			})
		}
	}
}
</script>
